<?php

namespace App\Http\Controllers\Admins;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admins\UserRequest;
use App\Repositories\BLL\UserBLL;

class PersonalController extends Controller
{
	private $userBLL;
	  	
    function __construct(UserBLL $user)
    {
        $this->userBLL = $user;
    }
    public function index(){
    		$currentUser = auth()->user();
		return view("admin.personal.index",
					['id'=>$currentUser->id
					,'name'=>$currentUser->name
					,'username'=>$currentUser->username
					,'email'=>$currentUser->email]);
	}
	
	public function save(UserRequest $request){
		$this->userBLL->savePersonal($request->all());
		return redirect(route('personal.index'));
	}
	
	public function psd(){
		return view("admin.personal.resetpsd");
	}
	
	public function psdsave(Request $request){
		$this -> validate($request,[
            'newpsd' => 'required|min:6',
            'confirmpsd'=> 'required',
        ],[
            'newpsd.required' => '密码不能为空',
            'confirmpsd.required' => '确认密码不能为空',
            'newpsd.min' => '密码不能少于6位',
        ]);
		
		$result = $this->userBLL->resetPassword($request->all());
		if($result){
			return redirect(route('personal.index'));
		}else{
			return redirect(route('personal.psd'));
		}
		
	}
}
